﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Authorit.API.Configuration;
using Authorit.API;

namespace DitaImport
{
	/// <summary>
	/// Stores configuration settings for the plugin.
	/// </summary>
	/// <seealso cref="ConfigReader"/>
	public class Config
	{
		/// <summary>
		/// Backing field for the <see cref="ElementsTopicContent"/> property
		/// </summary>
		private ReadOnlyCollection<string> elementsTopicContent;

		/// <summary>
		/// Gets the list of elements that define content in a topic
		/// </summary>
		public ReadOnlyCollection<string> ElementsTopicContent
		{
			get { return elementsTopicContent; }
		}
		
		/// <summary>
		/// Backing field for the <see cref="AitXmlNamespacePrefix"/> property
		/// </summary>
		private string aitXmlNamespacePrefix;

		/// <summary>
		/// Backing field for the <see cref="AitXmlNamespace"/> property
		/// </summary>
		private string aitXmlNamespace;

		/// <summary>
		/// Gets the Author-it XML namespace
		/// </summary>
		public string AitXmlNamespace
		{
			get { return aitXmlNamespace; }
		}


		/// <summary>
		/// Gets the prefix to use for the Author-it XML namespace when parsing XML using a namespace manager
		/// </summary>
		public string AitXmlNamespacePrefix
		{
			get { return aitXmlNamespacePrefix; }
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Config"/> class.
		/// </summary>
		public Config()
		{
			ReadConfiguration();  //Read the .config file and set the property values
		}

		/// <summary>
		/// Reads the configuration file for the plugin and sets values 
		/// for the properties of this instance of the <see cref="Config"/> class.
		/// </summary>
		public void ReadConfiguration()
		{
			this.elementsTopicContent = ConfigReader.GetSettingAsReadOnlyStringCollection(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.ElementsTopicContent));
			this.aitXmlNamespacePrefix = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.AitXmlNamespacePrefix));
			this.aitXmlNamespace = ConfigReader.GetSetting(ReflectionUtility.GetPropertyName(() => Properties.Settings.Default.AitXmlNamespace));
		}
	}
}
